<template>
  <kr-print-designer ref="printDesigner" :temp-value="value" :widget-options="widgets" @save="handleSave" />
</template>
<script>
export default {
  data() {
    return {
      index: '',
      value: {
        title: '条码设计器',
        width: 750,
        height: 550,
        pageWidth: 750,
        pageHeight: 550,
        tempItems: [],
      },
      widgets: [
        {
          type: 'braid-txt',
          isEdit: 0,
          title: '公司名称',
          value: '{公司名称}',
          defaultValue: '某某公司',
          name: 'companyName'
        },
        {
          type: "braid-image",
          title: "二维码",
          value: "@/assets/image/txm.png",
          name: 'qrCode'
        },
        {
          type: "bar-code",
          title: "条形码",
          value: "http://192.168.7.229/syy/file/files/view/5f9fb42dabebb4049ffbd019",
          name: 'barCode'
        },
      ]
    }
  },

  created() {
    this.index = this.$route.query.index
    try {
      let tempList = JSON.parse(localStorage.getItem('tempList')) || []
      this.value = tempList[this.index]
      this.widgets = this.value.type == 1 ? OutStockOptions : InStockOptions
    } catch (err) {
      console.error(err)
    }
  },
  methods: {
    handleSave(data) {
      let tempList = JSON.parse(localStorage.getItem('tempList')) || []
      tempList[this.index] = data
      localStorage.setItem('tempList', JSON.stringify(tempList))
      this.$router.back()
    },
    // 手动初始话模板数据
    initTemp(){
      this.$refs.printDesigner.initTemp(this.value,this.widgets)
    }
  },
}
</script>
